var express = require('express');
var router = express.Router();
const mongodb= require('../components/mongo');



/* GET home page. */
router.get('/',async function(req, res, next) {
   res.render('signupSample',{title:'signupSample'});
}).post('/',async function(req, res) {
   console.log(req.body);
   var m_uid = req.body.u_id;
   var m_password = req.body.password;
   const user_result = await mongodb.find("User",{u_id:m_uid});
   if( user_result.length > 0 ){
	   user_password = user_result[0].password;
	   if(user_password!=m_password){
		   res.json(
		   			   {
		   			       errno: 0,
		   			       errmsg: "",
		   			       data: {
		   			           res: false,
		   			           err: 2,
		   			       }
		   			   }
					)   
	   }else{
		   res.json({
			       errno: 0,
			       errmsg: "",
			       data: {
			           res: true,
			           u_id: user_result[0].u_id,
			           name: user_result[0].name,
			           password: user_result[0].password,
			           head_image: user_result[0].head_image,
			           email : user_result[0].email,
			           phone : user_result[0].phone,
			           hobby : user_result[0].hobby,
			           content : user_result[0].content,
						}
					})
	   }
   }else{
	   res.json(
	   			   {
	   			       errno: 0,
	   			       errmsg: "",
	   			       data: {
	   			           res: false,
	   			           err: 1,
	   			       }
	   			   }
				) 	  
		}
});



module.exports = router;